/* class Custtomer {
  custname: string;
  constructor(custname: string) {
    this.custname = custname;
  }
  buy() {}
}

// [object Function]
console.log(Object.prototype.toString.call(Custtomer));
let cust = new Custtomer("zs");
// [object Object]
console.log(Object.prototype.toString.call(cust)); */

class Pay {
  // 支付父类
  bank_card_no: string; // 捆绑银行卡号
  balance: number; // 银行卡余额
  cost: number; // 消费费用
  tokenid: string; // 登录后用户访问令牌
  constructor(
    bank_card_no: string,
    balance: number,
    cost: number,
    tokenid: string
  ) {
    this.bank_card_no = bank_card_no;
    this.balance = balance;
    this.cost = cost;
    this.tokenid = tokenid;
  }
  pay() {
    console.log("支付银行卡卡号：", this.bank_card_no);
  }
}

enum PayType {
  WebChat = 1,
  AliPay = 2,
  CloudFlashPayment = 3,
}

// 银行卡支付
class BandPay extends Pay {
  bank_network!: string; // 银行网点
  bankno_type!: string; // 银行卡类型
  bank_card_psw!: string; // 银行卡密码
  custname!: string; // 顾客姓名
}

// 移动支付
class MobilePay extends Pay {
  type: PayType;
  change: number; // 支付平台零钱
  opendid: string; // 用户识别身份id
  appid: string; // 微信小程序 appid
  constructor(
    bank_card_no: string,
    balance: number,
    cost: number,
    tokenid: string,
    type: PayType,
    change: number,
    opendid: string,
    appid: string
  ) {
    // super含义： 1.父类的构造方法，2.重新父类方法
    super(bank_card_no, balance, cost, tokenid);
    this.type = type;
    this.change = change;
    this.opendid = opendid;
    this.appid = appid;
  }

  pay() {
    super.pay();
    console.log("完成支付");
  }
}

class Customer {
  pay(payMethod: BandPay | MobilePay) {
    if (isMobilePay1(payMethod)) {
      console.log(payMethod.type);
    }

    /* if (isMobilePay(payMethod)) {
      // 获取不到MobilePay类型的字段
      console.log(payMethod.tokenid);
    } */
    /* if (payMethod instanceof BandPay) {
      console.log(payMethod.tokenid);
    } else if (payMethod instanceof MobilePay) {
      console.log(payMethod.appid);
    } */
  }
}

// 自定义守卫
function isMobilePay1(payMethod: BandPay | MobilePay): payMethod is MobilePay {
  return payMethod instanceof MobilePay;
}
/* function isMobilePay(payMethod: BandPay | MobilePay): boolean {
  return payMethod instanceof MobilePay;
} */

// 编译后式寄生式继承
let webChatPay = new MobilePay(
  "111",
  300,
  100,
  "ad",
  PayType.WebChat,
  10,
  "1123sfas",
  "adfsa2"
);

webChatPay.pay();

export {};

export {};
